package com.south.base.proxy.cglib;


import lombok.extern.slf4j.Slf4j;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * cglib代理
 *
 * @author Administrator
 * @date 2019/11/29 14:05
 */
@Slf4j
public class DynamicProxyHandler implements MethodInterceptor {
    private Object proxied;

    public DynamicProxyHandler(Object proxied) {
        this.proxied = proxied;
    }

    @Override
    public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
        log.info("proxy: {}, method: {},methodProxy: {}, args: {}", proxy.getClass(), method, methodProxy, Arrays.toString(args));
        return methodProxy.invoke(proxied, args);
    }
}
